package top.lywivan.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @desc
 * @author:ivan.liu
 */
public class NO22 {
    public static void allSituation(int level, int maxLevel, String s, List<String> res){
        if(level>maxLevel){
            res.add(s);
            System.out.println(s);
            return;
        }
        //左括号的情况
        String s1=s+"(";
        allSituation(level+1,maxLevel,s1,res);
        //右括号的情况
        String s2=s+")";
        allSituation(level+1,maxLevel,s2,res);
    }

    public static void recur(int left,int right,int n,String s,List<String> res){
        if(left==n&&right==n){
            res.add(s);
            System.out.println(s);
            return;
        }
        //左括号
        if(left<n){
            String s1=s+"(";
            recur(left+1,right,n,s1,res);
        }
        //右括号
        if(right<left){
            String s2=s+")";
            recur(left,right+1,n,s2,res);
        }
    }

    public static void main(String[] args) {
        NO22.recur(0,0,3,"",new ArrayList<>());
    }
}
